package com.yh.serviceImpl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yh.bean.User;
import com.yh.dao.UserDao;
import com.yh.service.UserService;

@Service
public class UserServiceImpl implements UserService{
    
	@Autowired
	private UserDao userDao;
	
	//用户注册增加用户
	@Override
	public int addUser(User user) {
		// TODO Auto-generated method stub
		return userDao.addUser(user);
			
	}
	
	//用户登陆查询用户
	@Override
	public User queryUser(User user) {
		// TODO Auto-generated method stubs
		return userDao.queryUser(user);
	}

	//用户忘记密码修改数据库密码
	@Override
	public int updatePwd(User user) {
		// TODO Auto-generated method stub
		return userDao.updatePwd(user);
	}

	//修改密码之前根据手机号和邮箱查询到对应的用户
	@Override
	public User queryUser2(User user) {
		// TODO Auto-generated method stub
		return userDao.queryUser2(user);
	}

	//后台查询用户数据并展示
	@Override
	public Map<String, Object> queryUser3(int currentPage) {
		// TODO Auto-generated method stub
		//获取第一页的数据
		//page对象是pagehelper jar提供的对象，PageInfo可以自定义，也可以使用pagehelper 插件提供的对象
		//第一个参数取第几页的数据，第二个参数表示一页显示多少条数据
		System.out.println("实现类="+currentPage);
		Page pageInfo=PageHelper.startPage(currentPage, 3);
		List<User> userList=userDao.queryUser3();
		System.out.println("测试"+userList);
		int totalPages=pageInfo.getPages();
		System.out.println("totalPages="+totalPages);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("userList", userList);
		map.put("totalPages", totalPages);
		return map;
	}

	//后台管理页面根据用户姓名模糊查询
	@Override
	public List<User> queryUser4(User user) {
		// TODO Auto-generated method stub
		/*Map map=new HashMap();
		map.put("realName", realName);*/
		return (List<User>) userDao.queryUser4(user);
	}

	//后台管理页面修改用户身份状态和发帖状态
	@Override
	public boolean updateUser(User user) {
		// TODO Auto-generated method stub
		int update=userDao.updateUser(user);
		if(update>0){
			return true;
		}else{
			return false;
		}
	}

	//后台管理页面删除用户信息
	@Override
	public boolean deleteUser(int uid) {
		// TODO Auto-generated method stub
		int delete=userDao.deleteUser(uid);
		if(delete>0){
			return true;
		}else{                 
			return false;
		}
	}

}
